var goEasy = new GoEasy({
	         appkey: 'BC-2051e252a3f843af83212c54789372be'
	    });
	    //GoEasy-OTP可以对appkey进行有效保护，详情请参考：GoEasy-Reference
	    
	    goEasy.subscribe({
		    channel: 'SelfServicePrinting',
		    onMessage: function(message){
		    	if(message.content==1){
		    		$("#paymentModal").attr("class","modal modal_dy hidden");
					$("#myModal").attr("class","modal modal_dy");
					$(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>支付成功，正在打印！"+message.content+"</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
			        settime_warn($("#btn_warn"));
					var dvdCheck=$("#dvdChoice").val();
					myPrint();
					if(dvdCheck==1){
						copyBanum();
					}
		    	}else{
		    		$(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>支付失败，请联系客服！"+message.content+"</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
			        settime_warn($("#btn_warn"));
		    	}
		        //alert('收到：'+message.content);
		        //document.getElementById("message").innerHTML = message.content + "<br/>";
		    }
		});
		
		function create(){
				
			//保存病人信息
				var orgcode=$("#orgcode").val();
				var onlyId=$("[name='banum_checkbox'][checked]").val();
				var combinationContent=$("[name='combination_checkbox'][checked]").val();
				var dvdCheck=$("#dvdChoice").val();
				var basepath=$("#basepath").val();
				if(onlyId==undefined){
					$(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请选择病案!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
					$("#print").attr("disabled",true);
					settime_warn($("#btn_warn"));
					
				}else if(combinationContent==undefined){
					$(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>请选择病案用途!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
					$("#print").attr("disabled",true);
					settime_warn($("#btn_warn"));
				}else{
					$("#paymentModal").attr("class","modal modal_dy ");
					$("#myModal").attr("class","modal modal_dy hidden");
					var check_id=$("[name='banum_checkbox'][checked]").attr("id");
					var check0=check_id.split("_")[0];
					var check1=check_id.split("_")[1];
					var check3=check_id.split("_")[2];
					var id=check1+"_"+check0+"_"+check3;
					
					$("#table_banum_party").html("");
					$("#table_banum_party").append("<tr>"+$("#"+id).html()+"</tr>");
					var fs=$("#input_fs").val();
					var banum=$("#dy_banum").val();
					var name=$("#partyName").val();
					var cardno=$("#certNumber").val();
					
					//保存打印记录
					$.ajax({  
		                    type:"POST",  
		                    url:basepath+"spmr/saveMed",  
		                    dataType:"json",  
		                    data:{onlyId:onlyId,combinationContent:combinationContent,orgcode:orgcode,fs:fs,
		                    		name:name,banum:banum,cardno:cardno},
		                    success:function(data){
		                    	var money=data*100;
		                    	//刻录收费50
		                    	if(dvdCheck==1){
		                    		money+=5000;
		                    	}
		                    	$("#hdfy").html("微信扫码后，请核对金额为"+money/100+"元。");
		                    	$.post("http://11.0.0.66:9090/phr/weChat/getWechatBizPayUrl.do?money="+1,
									{},
									function(data){
										var url = data["url"];
										$("#div_qr").empty();
										/* $("#div_qr").qrcode(utf16to8(url)); */
										$("#div_qr").qrcode({width:200,height:200,correctLevel:0,text:utf16to8(url)});  
									}, "json");
			                  
		                    },  
		                    error:function(){  
		                           $(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>支付接口调用失败!</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
		                           settime_warn($("#btn_warn"));
		                    }
				    });  
			}
			
	    }	
		
		function utf16to8(str) { //转码  
	    	var out, i, len, c;  
	        out = "";  
	        len = str.length;  
	        for (i = 0; i < len; i++) {  
	        	c = str.charCodeAt(i);  
	            if ((c >= 0x0001) && (c <= 0x007F)) {  
	            	out += str.charAt(i);  
	            } else
	            	if (c > 0x07FF) {  
	            		out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));  
	                	out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));  
	                	out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));  
	                } else {  
	                    out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));  
	                    out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));  
	                }  
	        }  
	        return out;  
	    }    